<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$ColumnType = 2; //栏目类型:0栏目内容分类,1新闻分类,2产品分类

if(!is_numeric(($_GET['ID']))) MsgBox (1,'您提交的参数有误！','-1');
$Rs = $db->SelectSQL("SELECT `ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ID = '" . $_GET['ID'] . "'");
if(count($Rs)==0){MsgBox (1,'不存在的产品类别！','-1');}
$ColumnRela = $Rs[0][0]; $ColumnName = $Rs[0][1];  $ColumnSort = $Rs[0][3]; unset($Rs); 
if ($_POST['Action'] == 'UpDate'){
	$_POST['ColumnRela'] == '' ? $NewColumnRela = $_GET['ID'] : $NewColumnRela = $_POST['ColumnRela'] . '|' . $_GET['ID'];
	$ColumnSort = is_numeric($_POST['ColumnSort']) ? $_POST['ColumnSort'] : 0;
	if ($NewColumnRela != $ColumnRela) { //当移动了栏目时产生
		$Count = $db->SelectSQL("SELECT count(ID) FROM `" . $dbprefix . "column` WHERE `ColumnRela` LIKE '%" . $_GET['ID'] . "%' && ID != '" . $_GET['ID'] . "'");
		if($Count[0][0]>0){AdminLog(1,$Lang,'修改产品类别失败，原因：无法对含有子类的产品类别进行移动操作！'); MsgBox (1,'操作失败，该类别下有子类存在，不可以移动到其它类别中！','-1');}
		$Count = $db->SelectSQL("SELECT count(ID) FROM `" . $dbprefix . "product` WHERE `ProductRela` LIKE '%" . $_GET['ID'] . "%'");
		if($Count[0][0]>0){AdminLog(1,$Lang,'修改产品类别失败，原因：无法对含有产品内容的类别进行移动操作！'); MsgBox (1,'操作失败，该类别下有产品内容存在，不可以移动到其它类别中！','-1');}
	}
	//修改
	$ColumnLevel = count(explode('|',$_POST['ColumnRela'])); //获取当前类别级数
	if($_POST['ColumnRela'] != '') { $ColumnLevel++; }
	$SQL = "UPDATE `" . $dbprefix . "column` SET `ColumnRela` = '" . $NewColumnRela . "',`ColumnName`='";
	$SQL .= $_POST['ColumnName'] . "',`ColumnLevel`='" . $ColumnLevel . "',`ColumnSort`='" . $ColumnSort . "' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;";	
	if($db->ExecuteSQL($SQL)){
		unset($Rs,$SQL,$ColumnLevel,$ColumnRela,$NewColumnRela);
		AdminLog(1,$Lang,'修改产品类别(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
		MsgBox (1,'类别修改成功！','ProductColumnManage.php?Lang=' . $Lang);
	} else {
		unset($Rs,$SQL,$ColumnLevel,$ColumnRela,$NewColumnRela);
		AdminLog(1,$Lang,'修改产品类别(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
		MsgBox (1,'类别修改失败！请检查您提交的数据是否正确！','1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script language="javascript">
function trim(str) {
	return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g,"");
}
function FormCheck(){
	if(trim(document.form1.ColumnName.value)==""){
		alert('类别名称必须填写！');
		document.form1.ColumnName.focus();
		return false;
	}
}
</script>
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
</head>

<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
	<td>&nbsp;</td>
	<td align="right">
		<input type="button" value="添加产品" onClick="javascript:location.href='ProductAdd.php?Lang=<?php echo $Lang?>'">
		<input type="button" value="产品管理" onClick="javascript:location.href='ProductManage.php?Lang=<?php echo $Lang?>'">		
		<input type="button" value="类别管理" onClick="javascript:location.href='ProductColumnManage.php?Lang=<?php echo $Lang?>'">
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form id="form1" name="form1" method="post" action="ProductColumuUpDate.php?Lang=<?php echo $Lang?>&ID=<?php echo $_GET['ID']?>" onsubmit="return FormCheck()">
  <tr class="odd">
    <td colspan="3" align="center" class="Main_Title">修改产品类别<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
  	<td width="16%" align="right">所属类别：</td>
  	<td width="38%">
<select name="ColumnRela" id="ColumnRela">
<option value="">==作为一级类别==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	if ($Rs[$i][0] != $_GET['ID']){ //跳过当前类别做为父级类别,不作显示
		for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与类别级数相同的空格
		$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级类别前不加空格符
		if(ParentID($ColumnRela) != $Rs[$i][0]){
			echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
		} else {
			echo '<option selected="selected" value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
		}
		unset($Spaces);
	}
}
?>  		
</select>
</td>
  	<td class="ippv">支持无限级分类</td>
  	</tr>
  <tr class="odd">
  	<td align="right">类别名称：</td>
  	<td><input name="ColumnName" type="text" class="input2" id="ColumnName" value="<?php echo Html($ColumnName)?>" maxlength="50" />
  		<span class="red">*</span></td>
  	<td>&nbsp;</td>
  	</tr>
  <tr class="odd">
  	<td height="30" align="right">自定义排序：</td>
  	<td><input name="ColumnSort" type="text" id="ColumnSort" value="<?php echo $ColumnSort;?>" size="5" maxlength="3" /></td>
  	<td class="ippv">升序(值越小越靠前)</td>
  	</tr>	
  <tr class="odd">
    <td height="30" align="right">&nbsp;</td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    	<input type="reset" name="button2" id="button2" value="重 置" class="submit" />
    	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" value="返 回" class="submit" onClick="javascript:location.href='ProductColumnManage.php?Lang=<?php echo $Lang?>'">
<input name="Action" type="hidden" id="Action" value="UpDate" /></td>
    <td>&nbsp;</td>
  </tr>
    </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
		注：1、为保证类别及产品内容结构性，不可以对含有子类或产品内容的类别进行移动操作；
		
		</td>
	</tr>
</table>
</body>
</html>